package com.dj.ms.support.feign;

import feign.RequestInterceptor;
import org.slf4j.MDC;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;

@Component
public class TraceIdFeignInterceptor {
    /**
     * 基于Feign的服务调用
     */
    @Bean
    public RequestInterceptor requestInterceptor() {
        return template -> {
            String traceId = MDC.get("traceId");
            if (traceId != null) {
                template.header("traceId", traceId);
            }
        };
    }
}
